package com.xgkj.diyiketang.task;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xgkj.diyiketang.ProtocolConst;
import com.xgkj.diyiketang.data.EatShowUserInfo;
import com.xgkj.diyiketang.http.CouponHttpRequest;
import com.xgkj.diyiketang.http.CouponHttpResponse;
import com.xgkj.diyiketang.http.engine.CouponHttpBaseTask;
import com.xgkj.diyiketang.http.engine.TaskResultCode;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrater on 2015/12/7.
 */
public class ApplySTListTask extends CouponHttpBaseTask {

    private String muserId;

    public ApplySTListTask(String clubId) {
        super();
        muserId = clubId;
    }

    @Override
    protected void processResponseData(CouponHttpResponse response) {
        JSONObject json = response.getBody();

        List<EatShowUserInfo> list = new ArrayList<EatShowUserInfo>();
        if (json != null) {
                list = JSON.parseArray(
                        json.getString(ProtocolConst.LIST_TAG),
                        EatShowUserInfo.class);
        }
        notifyTaskCompleted(TaskResultCode.SUCCESS, list);
    }

    @Override
    protected void prepareRequest() {
        super.prepareRequest();
        if (mPhase == TASK_PHASE_INIT) {
            CouponHttpRequest request = new CouponHttpRequest();
            JSONObject json = new JSONObject();
            json.put("clubId", muserId);
            request.setData(json.toString());
            request.setApiNo(ApiNo.APPLYSTLIST);
            addRequest(request);
        }
    }
}
